//
//  main.m
//  CopyDemo01
//
//  Created by FelixYin on 2020/4/19.
//  Copyright © 2020 FelixYin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Person.h"
#import "Student.h"

void test1(){
    NSString *str = [NSString stringWithFormat:@"FelixFelixFelixFelixFelixFelixFelixFelixFelixFelixFelixFelix"];
    
//    str RetainCount == 1  0x100518c80
    NSLog(@"str RetainCount == %ld  %p",str.retainCount,str);
    Person *person = [[Person alloc] init];
    person.name = str;
    person.age = 90;
    
//    person RetainCount == 1
    NSLog(@"person RetainCount == %ld",person.retainCount);
//0x100518c80 str RetainCount == 2 0x100518c80 name RetainCount == 2 (str 地址与name地址相同 所以引用计数为2)
    NSLog(@"%p str RetainCount == %ld %p name RetainCount == %ld",str,str.retainCount,person.name,person.name.retainCount);
    [str release];

    //0x100518c80 str RetainCount == 1 0x100518c80 name RetainCount == 1
    NSLog(@"%p str RetainCount == %ld %p name RetainCount == %ld",str,str.retainCount,person.name,person.name.retainCount);
}

void test2(){
    Student *stu = [[Student alloc] init];
    stu.name = @"FelixYin";
    stu.teacherName = @"Micke";
    
    Student *stu2 = [stu copy];
    stu2.name = @"Jacky";
    
//    stu 0x100423ca0  stu2 0x100423d00  创建一个新的对象
    NSLog(@"stu %p  stu2 %p",stu,stu2);
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
//        test1();
        test2();
    }
    return 0;
}
